package com.javabloger.orm;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.sql.DataSource;

public   class SimpleDataSource  implements DataSource {
	
	private String driverClassName;
	private String url;
	private String username;
	private String password;
	
	public SimpleDataSource   (String driverClassName ,String url,String username,String password) {
			 this.driverClassName=driverClassName; 
			 this.url=url;
			 this.username=username;
			 this.password=password;
	}
	
	public SimpleDataSource   ( ) {
	}
	
	public  void setDriverClassName(String driverClassName) {
		this.driverClassName = driverClassName;
	}

	public  void setUrl(String url) {
		this.url = url;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public synchronized Connection getConnection() throws SQLException {
		 Connection conn = null;
			try {
				 Class.forName( driverClassName);
				 conn = DriverManager.getConnection(url,username,password);  
			} 
			catch ( Exception e) {
				e.printStackTrace();
			}
		return conn;
	}


	public synchronized Connection getConnection(String username, String password) throws SQLException {
		 Connection conn = null;
			try {
				 Class.forName( driverClassName);
				 conn = DriverManager.getConnection(url,username,password);  
			} 
			catch ( Exception e) {
				e.printStackTrace();
			}
		return conn;
	}

	public PrintWriter getLogWriter() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public int getLoginTimeout() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public void setLogWriter(PrintWriter out) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	public void setLoginTimeout(int seconds) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	
	public boolean isWrapperFor(Class<?> iface) throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	
	public <T> T unwrap(Class<T> iface) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	
}
